
package sceneInfo;

/** This class holds visual information about flag
 * 
 */

public class FlagInfo extends ObjectInfo
{

	private static final long serialVersionUID = 1L;
	
	private char type;  // p|g
	private char m_pos1;  // t|b|l|c|r
	private char m_pos2;  // l|r|t|c|b
	private int m_num;    // 0|10|20|30|40|50
	private boolean m_out;

	/**
	 * Default Constructor
	 *
	 */
	public FlagInfo()
	{
		super("flag");
		type = ' ';
		m_pos1 = ' ';
		m_pos2 = ' ';
		m_num = 0;
		m_out = false;
	}

	/** Constructor to set all of the parameters by hand
	 * 
	 * @param flagName Flag name
	 * @param _type Flag Type
	 * @param pos1 Position 1
	 * @param pos2 Position 2
	 * @param num Flag number
	 * @param out Out of field of play
	 */
	public FlagInfo(String flagName, char _type, char pos1, char pos2,
                  int num, boolean out)
	{
		super(flagName);
		testType(_type);
		type = _type;
		testPos(pos1);
		m_pos1 = pos1;
		testPos(pos2);
		m_pos2 = pos2;
		testNum(num);
		m_num = num;
		m_out = out;
	}
	/** Constructor to set all of the parameters by hand, except the flag name
	 * 
	 * @param _type Flag Type
	 * @param pos1 Position 1
	 * @param pos2 Position 2
	 * @param num Flag number
	 * @param out Out of field of play
	 */
	public FlagInfo(char _type, char pos1, char pos2, int num, boolean out)
	{
		super("flag");
		testType(_type);
		type = _type;
		testPos(pos1);
		m_pos1 = pos1;
		testPos(pos2);
		m_pos2 = pos2;
		testNum(num);
		m_num = num;
		m_out = out;
	}

  	/** Get the flag number
  	 * 
  	 * @return the number
  	 */
  	public int getNum() {
  		return m_num;
  	}

  	/** Set the flag number
  	 * 
  	 * @param m_num the number
  	 */
  	public void setNum(int m_num) {
  		testNum(m_num);
  		this.m_num = m_num;
  	}	

	/** Check if the flag is outside the field of play
	 * 
	 * @return true if it is outside the field of play
	 */
	public boolean isOut() {
		return m_out;
	}
	
	public String toString(){
			return "[Flag (" + (type!=' '? type: "")+ (m_pos1!=' '? m_pos1: "") + (m_pos2!=' '? m_pos2: "")+ (m_num!=' '? m_num: "")+") at "
			+ getDistance()+"m in dir:"+getDirection()+"]";
	}


	/** Set whether the flag is outside the field of play
	 * 
	 * @param m_out True if it is outside the field of play
	 */
	public void setOut(boolean m_out) {
		this.m_out = m_out;
	
	}
	/** Get the position1
	 * 
	 * @return position1
	 */
	public char getPos1() {
		return m_pos1;
	}

	/** Set the position1
	 * 
	 * @param m_pos1 The position1
	 */
	public void setPos1(char m_pos1) {
		testPos(m_pos1);
		this.m_pos1 = m_pos1;
	}

	/** Get the position2
	 * 
	 * @return position2
	 */
	public char getPos2() {
		return m_pos2;
	}

	/** Set the position2
	 * 
	 * @param m_pos2 The position2
	 */
	public void setPos2(char m_pos2) {
		testPos(m_pos2);
		this.m_pos2 = m_pos2;
	}

	/** Get the flag type
	 * 
	 * @return Flag type
	 */
	public char getFlagType() {
		return type;
	}

	/** Set the flag type
	 * 
	 * @param type The flag type
	 */
	public void setFlagType(char type) {
		testType(type);
		this.type = type;
	}

	//Test the type field to make sure it is valid
	private void testType(char type){
		if(type != 'p' && type != 'g' && type != ' '){
			throw new IllegalArgumentException("The flag type must be 'p', 'g' or ' '");
		}
	}
	
	//	Test the pos1 field to make sure it is valid
	private void testPos(char p1){
		if(p1 != 't' && p1 != 'b' && p1 != 'l' && p1 != 'c' && p1 != 'r' && p1 != ' '){
			throw new IllegalArgumentException("The flag pos must be 't', 'b', 'l', 'c', 'r', ' '");
		}
	}
	
	//	Test the num field to make sure it is valid
	private void testNum(int num){
		if(num != 0 && num != 10 && num != 20 && num != 30 && num != 40 && num != 50 ){
			throw new IllegalArgumentException("The flag num must be 0, 10, 20, 30, 40 or 50");
		}
	}
	
}
